<%@page import="com.hhit.collaborative_learning.entity.QuestionAnswer"%>
<%@page import="com.hhit.collaborative_learning.entity.Question"%>
<%@page
	import="com.hhit.collaborative_learning.dao.impl.PublicDaoImplMySql"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page isELIgnored="false"%>
<%
	String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String questionId=request.getParameter("questionId");
PublicDaoImplMySql dao=new PublicDaoImplMySql();
HashMap<String, Object> map=dao.getQuestionById(Integer.parseInt(questionId));
Question q=(Question)map.get("question");
ArrayList<QuestionAnswer> answerlist=(ArrayList<QuestionAnswer>)map.get("answerlist");
String userId=q.questionUserId+"";
request.setAttribute("question", q);
request.setAttribute("answerlist", answerlist);
request.setAttribute("questionUserId", userId);
%>


<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="<%=basePath%>css/bootstrap.css" media="all"
	rel="stylesheet" />
<link href="<%=basePath%>css/avatar.css" media="all" rel="stylesheet" />
<link href="<%=basePath%>css/btn.css" media="all" rel="stylesheet" />
<link href="<%=basePath%>css/icon.css" media="all" rel="stylesheet" />
<link href="<%=basePath%>css/pagination.css" media="all"
	rel="stylesheet" />

<link href="<%=basePath%>css/index.css" media="all" rel="stylesheet" />

<link href="<%=basePath%>css/mini.css" media="all" rel="stylesheet" />
<link href="<%=basePath%>css/font-awesome.min.css" media="screen"
	rel="stylesheet" />
<!-- [if IE 7]-->
<link href="<%=basePath%>css/font-awesome-ie7.min.css" media="screen"
	rel="stylesheet" />

<link href="<%=basePath%>css/common-ask.css" media="screen"
	rel="stylesheet" />
<link href="<%=basePath%>css/ask_float_block.css" media="screen"
	rel="stylesheet" />
<!-- <link href="<%=basePath%>css/editor.css" media="screen" -->
<!-- 	rel="stylesheet" /> -->

<script src="<%=basePath%>js/application.js"></script>
<script src="<%=basePath%>js/jquery.js"></script>
<script src="<%=basePath%>js/jquery.cookie.js"></script>
<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!-- [if lt IE 9]-->
<script src="<%=basePath%>js/html5shiv.min.js"></script>
<!-- [endif]-->
<script type="text/javascript">
	//             var username = 'u013534446';
	//             var oper_username = 'u013534446';
	//             document.domain="csdn.net";
</script>

<!-- <script src="<%=basePath%>js/mini.js"></script> -->
<script src="<%=basePath%>js/dscroll.js"></script>
<!-- <script src="<%=basePath%>js/cnick.js"></script> -->



<!-- <script src="<%=basePath%>js/wmd.js"></script> -->
<!-- <script src="<%=basePath%>js/showdown.js"></script> -->
<!-- <script src="<%=basePath%>js/prettify.js"></script> -->

<!-- <script src="<%=basePath%>js/marked.js"></script> -->
<!-- <script src="<%=basePath%>js/editor.js"></script> -->

<script type="text/javascript" src="<%=basePath%>js/csdn.js"></script>
<script type='text/javascript' src='<%=basePath%>js/ask_question.js'></script>
<script type='text/javascript'
	src='<%=basePath%>js/jquery.autocomplete.min.js'></script>
<script type='text/javascript' src='<%=basePath%>js/xheditor.js'></script>
<script type="text/javascript"
	src='<%=basePath%>js/xheditor_lang/zh-cn.js'></script>
<link type='text/css' rel='Stylesheet'
	href='<%=basePath%>css/jquery.autocomplete.css' />
</head>
<body id='questions-show'>
	<div class="main clearfix">
		<div style="margin-bottom: 10px;"></div>

		<div class="persional_property">
			<div class="second_nav_con">
				<dl class="second_nav">
					<dd class="active">
						<a href="<%=basePath%>questions/questions.jsp" target="_top">全部问答</a>
					</dd>
					<dd class="">
						<a href="<%=basePath%>questions/myquestion.jsp"
							onclick="checkLogin()">我的问答</a>
					</dd>
					<dd class="">
						<a href="<%=basePath%>questions/askquestion.jsp"
							onclick="checkLogin()">我要提问</a>
					</dd>
					<dd class="">
						<a href="<%=basePath%>questions/search.jsp?type=4" target="_blank">搜索</a>
					</dd>
				</dl>
			</div>
		</div>
		<script type="text/javascript">
			var utag2=[];
			jQuery(document).ready(initDiggs);
// 			window.onload=initDiggs;
// 			$(document).ready(function(){
// 				initDiggs();
// 			});
// 			$(initDiggs);
			function initDiggs(){
				var username = $.cookie("userId");
			    var digged = [];
			    var digged2 = [];
			    var cookieval = $.cookie("q_digged");
			    var cookieval2=$.cookie("qa_digged");
			    if (cookieval&&cookieval2) {
			        digged = cookieval.split(",");
			        digged2 = cookieval2.split(",");
			    }
			    $(".approve").each(function () {
			        var $this = $(this);
			        var id = $this.attr("id");
			        var rel=$this.attr("rel");
			        if(rel){
				        if (digged.contain(id)) {
				        	$this.attr("title","已经顶过");
				        	$this.attr("id","");
				        }
			        }else{
			        	if (digged2.contain(id)) {
				        	$this.attr("title","已经顶过");
				        	$this.attr("id","");
				        }
			        }
			    });
			    $(".approve").click(function () {
			    	var $this=$(this);
			        if (!username) {
			            if (confirm("您的操作必须登录，是否登录？")) {
			                top.location.href = basePath+"login.jsp?link="+encodeURIComponent(links[2]+"/"+links[3]);
			                return false;
			            }
			            return false;
			        }
			        var qId=$this.attr("id");
			        if(!qId){
			        	return false;
			        }
			        var rel=$this.attr("rel");
			        var action=0;
			        if(rel){
			        	action=1;
			        }
			        $.post("<%=basePath%>DiggedQServlet",{userId:username,qId:qId,action:action},function (data,status) {
			        		$this.attr("id","");
			        		if(rel){
				                digged.push(parseInt(qId));
				                $.cookie("q_digged", digged.join(),{path:"/"});
			        		}else{
			        			digged2.push(parseInt(qId));
				                $.cookie("qa_digged", digged2.join(),{path:"/"});
			        		}
			                var num=$this.attr("num");
			                $this.text(parseInt(num)+1);
			                $this.attr("title","已经顶过");
			        });
			        return false;
			    });
			}
					Array.prototype.contain = function(val){
						for(var i=0;i<this.length;i++){
							if(this[i] === val){
								return true;
							}
						}
						return false;
					}
				</script>

		<link href="<%=basePath%>css/ask_question_detail.css" media="screen"
			rel="stylesheet" />
		<link href="<%=basePath%>css/ask_index_A.css" media="screen"
			rel="stylesheet" />
		<script src="<%=basePath%>js/text-stretch.js"></script>
		
		<div class="persion_section">

			<div class="common_con clearfix">
				<div class="q_operate">
					<c:choose>
						<c:when test="${requestScope.questionUserId eq cookie.userId.value}">
							<p>我的提问&#47; &nbsp;&nbsp; ${requestScope.question.questionTime}创建</p>
						</c:when>
						<c:otherwise>
							<p><a href="<%=basePath%>my.jsp?userId=${requestScope.questionUserId}" target="_blank">${requestScope.question.questionUserName}</a>的提问&#47; &nbsp;&nbsp; ${requestScope.question.questionTime}创建</p>
						</c:otherwise>
					</c:choose>
					
					<c:if test="${requestScope.questionUserId eq cookie.userId.value && requestScope.question.state eq 0}">
						<div class="operate_style">
							<div class="operate_style_label">
								操作<i class="icon-caret-down"></i>
							</div>
							<ul>
								<li><a href="<%=basePath%>questions/askquestion.jsp?questionId=<%=questionId%>">编辑</a>
								</li>
<!-- 								<li><a href="javascript:void(0);" class="reward_btn" -->
<!-- 									onclick="show_reward_pop('popup_reward');">悬赏</a></li> -->
								<li class="arrow"></li>
							</ul>
						</div>
					</c:if>
				</div>
				<div class="questions_detail_con">
					<dl>
						<dt>${requestScope.question.questionTitle}</dt>
						<div class="tags">
							<c:forEach items="${requestScope.question.questionTag}" var="tag">
							<a href="javascript:void(0);" target="_blank">${tag}</a> 
							</c:forEach>

						</div>
						<dd id="cut_intro">
							${requestScope.question.questionContent}
						</dd>
					</dl>

				</div>
				<div class="focus_bar_con" id="question_181930">
<!-- 					<span class="collection" style="margin-right: 15px;"> <a -->
<!-- 						class="collection" data-method="post" data-remote="true" -->
<!-- 						href="javascript:void(0);" -->
<!-- 						rel="nofollow" title="收藏"></a> -->
<!-- 					</span> <span class="interval">|</span> -->
					<div id="question_181930_vote">
						<a class="approve" href="javascript:void(0);" rel="nofollow" id="<%=questionId %>" num="${requestScope.question.questionDigged}"
							title="好问题，顶！">${requestScope.question.questionDigged}</a>
					</div>
				</div>
				<div class="answer_jump">
					<a href="#answer_form">我要回答</a>
				</div>
			</div>

			<div class="common_con clearfix">
				<div class="answer_sort_con  q_operate">
					<p>${requestScope.question.questionAnswerNum}个回答</p>
				</div>
				<div class="answer_list" >
					<c:forEach items="${requestScope.answerlist}" var="answer">
					
					<div 
					<c:choose>
						<c:when test="${answer.isBest eq 1}">
							class="answer_accept"
						</c:when>
						<c:otherwise>
							class="answer_detail_con"
						</c:otherwise>
					</c:choose> 
					 id='answer_${answer.answerId}'>
						<dl class="clearfix">
							<dt>
								<img alt="${answer.userNickName}"
									src="<%=basePath %>userIcons/${answer.userIcon}"
									style="width:35px; height:35px;" username="${answer.userNickName}" />
							</dt>
							<dd class="answer_name">
								<a class="user_name" href="javascript:void(0);"
									target="_blank">${answer.userNickName}</a>
							</dd>
							<c:if test="${requestScope.questionUserId eq cookie.userId.value && requestScope.question.state eq 0}">
							<dd class="is_accept">
								<a href="javascript:void(0);" onclick="accept('${answer.answerId}')">采纳</a>
							</dd>
							</c:if>
							<c:if test="${answer.isBest eq 1}">
							<dd class="has_accept">
								已采纳
							</dd> 
							</c:if>
						</dl>
						<div
							style="margin: 0 20px 10px;font-size: 14px;color: #666;line-height: 24px;word-break: break-all;word-wrap: break-word;">
							${answer.answerContent}
						</div>
						<div class="focus_bar_con nobg_color">
							<span class="answer_time">${answer.answerTime}</span> 
							<div id="answer_${answer.answerId}_vote">
								<a class="approve"  href="javascript:void(0);" rel="" id="${answer.answerId}" num="${answer.answerDigged}"
									title="好答案，顶！">${answer.answerDigged}</a>
							</div>
							<span class="interval">|</span>
							<a href="javascript:void(0);"
								class="comment" onclick="checkLogin();$('#answer_${answer.answerId}_comments').toggle();">
								评论${answer.answerComNum}</a> 
							
						</div>
					</div>

					<div id="answer_${answer.answerId}_comments">
						<div class="comment_pointer">
							<span></span>
						</div>

						<div id="answer_${answer.answerId}_comment_box_con" class="comment_box_con">
							<div class="comment_scroll_con" answerId="${answer.answerId}">
								<div id="answer_${answer.answerId}_comment_form" class="comment_form">
									<form accept-charset="UTF-8" action="/answers/67576/comments"
										class="new_answer_comment" data-remote="true"
										id="new_answer_comment_${answer.answerId}" method="post">
										<div style="display:none">
											<input name="utf8" type="hidden" value="&#x2713;" />
										</div>
										<input class="reply_input" id="comment_${answer.answerId}_form"
											name="answer_comment[body]" placeholder="回复 ${answer.userNickName}"
											type="text" /> <input type="button" value="评论" onclick="reply('${answer.answerId}')"
											class="reply_submit">
									</form>
								</div>
								<c:forEach items="${answer.list}" var="comment">
									<dl id="answer_comment_${comment.commentId}">
									<dt>
									  <a href="javascript:void(0);" target="_blank">
									      <img alt="${comment.userName}" src="<%=basePath %>userIcons/${comment.userIcon}" style="width:30px; height:30px;" username="${comment.userName}" />
									</a>  
									</dt>
									<dd class="comment_content">
									  <em><a class="user_name" href="javascript:void(0);" target="_blanlk">${comment.userName}</a></em>
									 ${comment.commentContent}
									</dd>
									<dd class="comment_reply">
									  <span>${comment.commentTime}</span>
									  <a href="javascript:void(0);" onclick="reply_comment('${answer.answerId}','${comment.commentId}')"> 回复</a>
									</dd>
									</dl>
								</c:forEach>
							</div>
						</div>
					</div>
					<c:choose>
						<c:when test="${answer.answerComNum gt 0}">
							<script type="text/javascript">
								Creatscroll('answer_${answer.answerId}_comment_box_con', 350);
							</script>
						</c:when>
						<c:otherwise>
							<script type="text/javascript">
								Creatscroll('answer_${answer.answerId}_comment_box_con', 350);
								$('#answer_${answer.answerId}_comments').hide();
							</script>
						</c:otherwise>
					</c:choose>
					
					
					</c:forEach>

				</div>


				<dl class="answer_form_con">
					<form accept-charset="UTF-8" action="" class="new_answer"
						id="answer_form" method="post">
						<dd class="form_textarea" style="position:relative;">
							<textarea id="editor" name="answer[body]" style="height: 200px;resize:none;" onclick="checkLogin(1)"></textarea>
						</dd>
						<dd class="form_submit">
							<input type="button" value="我要回答" class="form_submit_btn" onclick="submit_answer()"/>
						</dd>
						<dd class="point_arrow"></dd>
					</form>
				</dl>


<!-- 				<script type="text/javascript" src="<%=basePath%>js/question_comment.js"></script> -->


				<script type="text/javascript">
					function accept(answer){
						if(confirm("答案一旦采纳，无法修改!")){
							$.post("<%=basePath%>AcceptServlet",{qId:<%=questionId%>,aId:answer},function(data,status){
								if(data=='true'){
									alert("采纳成功！");
									top.location.reload();
								}
							});
						}
					}
					function checkLogin(type){
						if($.cookie("userId")){
							return true;
						}
						if(confirm("需要登录，是否登录?")){
							var links=top.location.href.substring(7).split("/");
							if(type==1){
								top.location.href="<%=basePath%>login.jsp?link="+encodeURIComponent(links[2]+"/"+links[3]+"&stepinto=answer_form");
							}else{
								top.location.href="<%=basePath%>login.jsp?link="+encodeURIComponent(links[2]+"/"+links[3]);
							}
							return false;
						}
						return false;
					}
					function submit_answer(){
						if(checkLogin()){
							var answer=$("#editor").val().trim();
							if(answer){
								$.post("<%=basePath%>AnswerQuestionServlet",{qId:<%=q.questionId%>,userId:$.cookie("userId"),content:encodeURIComponent(answer)},function(data,status){
									if(data=='true'){
										alert("回答成功");
										//prepend()
										showConfirm=false;
										if(top.location.href.indexOf("&")>0){
											top.location.href=top.location.href.substring(0,top.location.href.indexOf("&"));
										}else{
											top.location.reload();							
										}
									}
								});
							}else{
								alert("回答不能为空！");
							}
						}
					}
				</script>


				<div id="popup_reported" class="popup_reported"></div>
			</div>
		</div>


		<script>
			function reply(answerId){
				var content=$("#comment_"+answerId+"_form").val();
				$.post("<%=basePath%>ReplyAnswerServlet",{con:content,userId:$.cookie("userId"),answerId:answerId},function(data,status){
					if(data=='true'){
						alert("回复成功!");
						top.location.reload();
					}
				});				
			}
			function reply_comment(id, answer_comment_id) {
				var nickname = $(
						"#answer_comment_" + answer_comment_id + " em a")
						.text();
				$("#comment_" + id + "_form").val("回复" + nickname + ": ");
			}

			function show_reward_pop(popid) {
				$('#popup_mask').css({
					opacity : 0.5,
					width : $(document).width() + 'px',
					height : $(document).height() + 'px'
				});

				$('#popup_mask').css("display", "block");
				$('#' + popid).fadeIn("slow");
			}

			function hide_report_pop(popid) {
				$('#' + popid).fadeOut("fast");
				$('#popup_mask').css("display", "none");
			}

		</script>

	</div>


	<div id="popup_mask" class="marker"></div>
	<div id="pop_win"
		style="position: absolute;background: none repeat scroll 0 0 #FFFFFF;z-index: 10000;border: 1px solid #DCDCDC;"></div>

	<!-- script id="noticeScript" type="text/javascript" charset="utf-8" btnId="header_notice_num" wrapId="note1" count="5" subCount="5" src="//static.csdn.net/public/common/toolbar/js/notify.js"></script -->


<!-- 	<script src="http://c.csdnimg.cn/rabbit/tracking-ad/main.js"></script> -->
<!-- 	<script -->
<!-- 		src="/assets/libs/jquery.form-970fa25a8fc7698f768416b39f738706.js"></script> -->
<!-- 	<script type="text/javascript" -->
<!-- 		src="http://c.csdnimg.cn/pubfooter/js/publib_footer.js"></script> -->
<!-- 	<script id="csdn-toolbar-id" btnId="header_notice_num" wrapId="note1" -->
<!-- 		count="5" subCount="5" type="text/javascript" -->
<!-- 		src="//static.csdn.net/public/common/toolbar/js/toolbar.js"></script> -->

<!-- 	<script -->
<!-- 		src="/assets/apps/ask_float_block-66e526b2f7ad833cfe7515f51590738e.js"></script> -->

<!-- 	<script type="text/javascript"> -->
<!-- 		showMini(".help_peer_con,.technology_hot_person,.mod_glory_info,#scrolldiv,.hot_person_list,.tutor_list,.all_honnor_roll,.honnor_roll,.my_info"); -->
<!-- 	</script> -->
</body>
</html>
